﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class AssetBundleMenuItem
{

    [MenuItem("Assets/AssetBundle/Set AssetBundle By Path")]
    static public void SetAssetBundleByPath()
    {
        foreach (var obj in Selection.objects)
        {
            var assetPath = AssetDatabase.GetAssetPath(obj);
            var assetImporter = AssetImporter.GetAtPath(assetPath);

            string assetBundleName = assetPath.Substring(assetPath.IndexOf("/") + 1);
            assetImporter.assetBundleName = assetBundleName;
        }
    }


    [MenuItem("Assets/AssetBundle/Set folder AssetBundle none")]
    static public void SetFolderAssetBundleByPath()
    {
        UnityEngine.Object[] arr = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);


        foreach (var obj in arr)
        {
            var tmpPath = AssetDatabase.GetAssetPath(obj);
            if (tmpPath.EndsWith(".meta"))
            {
                continue;
            }
            var assetImporter = AssetImporter.GetAtPath(tmpPath);
            assetImporter.assetBundleName = "";
        }
    }

    //[MenuItem("Assets/Create/UGUI Sprite Assets", false, 10)]
    //static void CreateSpriteAsset()
    //{
    //    var assetPath = EditorUtility.SaveFilePanelInProject("选择文件路径", "", "asset", "",
    //                                                            GetSelectedPathOrFallback());
    //    if (!string.IsNullOrEmpty(assetPath))
    //    {
    //        SpriteAssets spriteAssets = ScriptableObject.CreateInstance<SpriteAssets>();
    //        List<Sprite> sprites = new List<Sprite>();
    //        foreach (Object tex in Selection.GetFiltered(typeof(Object), SelectionMode.Assets))
    //        {
    //            string filePath = AssetDatabase.GetAssetPath(tex);
    //            Object[] objects = AssetDatabase.LoadAllAssetsAtPath(filePath);
    //            foreach (Object obj in objects)
    //            {
    //                Sprite sprite = obj as Sprite;
    //                if (sprite != null)
    //                {
    //                    sprites.Add(sprite);
    //                }
    //            }
    //        }

    //        sprites.Sort((a, b) => string.Compare(a.name, b.name));
    //        spriteAssets.AddSpriteList(sprites);
    //        AssetDatabase.CreateAsset(spriteAssets, assetPath);
    //    }
    //}

}
